package com.ray.depot.util;

import java.util.ArrayList;
import java.util.List;

import com.ray.api.service.UcenterApiService;
import com.ray.auth.system.table.entity.Dict;
import com.ray.auth.system.table.entity.Organization;
import com.xiaoleilu.hutool.util.ObjectUtil;

public class DictJsonUtil {
	public  String NAME = "dictJson";
	private  List<String> list = new ArrayList<String>();

	public  List<String> getList() {
		return list;
	}

	/**
	 * 添加组织数据
	 * 
	 * @param name
	 * @param orgList
	 */
	public  void addOrg(String dictType, List<Organization> orgList) {
		 StringBuilder builder = new StringBuilder();
         builder.append("var ").append(dictType).append(" = {");
         for(Organization org:orgList){
        	 builder.append("'").append(org.getOrgId()).append("':'")
        	 .append(org.getOrgName()).append("',");
         }
         builder.append("'O':''};");
         list.add(builder.toString());
	}

	public  void clear() {
		list.clear();
		
	}
  
	
	/**
     * 添加字典
     * @param dictType
     * @param appList
     */
	public  void addDict(String dictType, List<Dict> dictList) {
		StringBuilder builder = new StringBuilder();
        builder.append("var ").append(dictType).append(" = {");
        for(Dict dict:dictList){
       	 builder.append("'").append(dict.getValue()).append("':'")
       	 .append(dict.getName()).append("',");
        }
        builder.append("'O':''};");
        list.add(builder.toString());
	}

	public  void addDict(UcenterApiService ucenterApiService, String...dictTypes) {
		if(ObjectUtil.isNotNull(dictTypes)){
			for(String type:dictTypes){
				List<Dict> lists = ucenterApiService.queryDictsByDictType(type);	
				addDict("_"+type, lists);
			}
		}
	}

	



}
